// pages/fpReserve/fpReserve.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    value: 5,
    step_list: [{
        id: 1,
        name: '发起服务',
        img: '',
        time: ''
      },
      {
        id: 2,
        name: '获取需求',
        img: '',
        time: ''
      },
      {
        id: 3,
        name: '线上邀约',
        img: '',
        time: ''
      },
      {
        id: 4,
        name: '邀约面谈',
        img: '',
        time: ''
      },
      {
        id: 5,
        name: '准备签约',
        img: '',
        time: ''
      },
    ],
    active: 0,
    btnText: '下一步',
    show: false,
    select: [{
      name: '服务有礼',
      index: 0
    }, {
      name: '专业讲师',
      index: 0
    }, {
      name: '最佳指导',
      index: 0
    }],
    list: {},
    Model: false,
    typeId: null,
    user: {}
  },
  dialonClose(){
    this.setData({
      dial:false
    })
  },
  phoneCall(e) {
    wx.makePhoneCall({
      phoneNumber: this.data.user.phone
    })
  },
  recommend(id) {
    var that = this;
    app.ports.api40({
      data: {pk: id}
    }).then((res) => {
      that.data.comUser = [];
      that.data.comUser[1] = {name: res.data.first.nickname};
      that.data.comUser[2] = {name: res.data.second.nickname};
      that.setData({
        comUser: that.data.comUser
      })
    }).catch(() => {
      console.error("获取邀请关系报错了！")
    })
  },
  user(info) {
    var that = this;
    getApp().ports.yhxx({
      id: info
    }).then((res) => {
      var list = that.data.list;
      console.log(res)
      var res = res.data;
      list.img = res.avatarUrl;
      list.name = res.nickname;
      list.phone = res.phone;
      that.setData({
        list: list
      })
    }).catch(() => {
      console.error('出啥错了？');
    });
  },
  stay(e) {
    var that = this;
    var value = e.detail.value;
    var data = {
      remark: value
    }
    console.log('===================================')
    var step_list = that.data.step_list;
    switch (Number(that.data.type)) {
      case 3:
        getApp().ports.fanpgdzt({
          data: data,
          id: that.data.list.id
        }).then((res) => {
          var res = res.data;
          // that.user(res.marketer)
          res.time = app.timeFormat(res.createTime, true)
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.finishTime, false, true)
          if (res.stage == 5) {
            that.data.btnText = '订单已完成'
          }
          that.setData({
            list: res,
            step_list: step_list,
            btnText: that.data.btnText
          })
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
      case 5:
        getApp().ports.hfgdzt({
          data: data,
          id: that.data.list.id
        }).then((res) => {
          var res = res.data;
          that.user(res.marketer)
          res.time = app.timeFormat(res.createTime, true);
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.finishTime, false, true)
          if (res.stage == 5) {
            that.data.btnText = '订单已完成'
          }
          that.setData({
            list: res,
            step_list: step_list,
            btnText: that.data.btnText
          })
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
      case 6:
        getApp().ports.zzgdzt({
          data: data,
          id: that.data.list.id
        }).then((res) => {
          var res = res.data;
          that.user(res.marketer)
          res.time = app.timeFormat(res.createTime, true)
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.finishTime, false, true)
          if (res.stage == 5) {
            that.data.btnText = '订单已完成'
          }
          that.setData({
            list: res,
            step_list: step_list,
            btnText: that.data.btnText
          })
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
    }
  },
  api(data) {
    var that = this;
    var statuss = ['待审核', '待上架', '出售中', '已出售'];
    var type = that.data.type;
    var data = data;
    var step_list = that.data.step_list;
    if (type == 3) {
      data.housePreuploadOrderId = that.data.id
      getApp().ports.fanpgd({ //放盘
        data: data
      }).then((res) => {
        var res = res.data;
        // res.comment = res.housePreuploadOrder.comment
        // res.rate = res.housePreuploadOrder.rate
        that.user(res.marketer)
        res.time = app.timeFormat(res.createTime, true)
        step_list[0].time = app.timeFormat(res.createTime, false, true)
        step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
        step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
        step_list[3].time = app.timeFormat(res.interviewTime, false, true)
        step_list[4].time = app.timeFormat(res.finishTime, false, true)
        if (res.stage == 5) that.data.btnText = '订单完成'
        if(res.stage == 2){
          that.setData({
            show:true
          })
        }
        console.log(res, '成功');
        that.setData({
          list: res,
          step_list: step_list,
          client: that.data.user.client,
          btnText: that.data.btnText,
          finished:0
        })
        that.recommend(that.data.user.client)
        that.history()
      }).catch(() => {
        console.error('出啥错了？');
      });
    } else if (type == 5) { //好房
      data.demandOrderId = that.data.id
      console.log(that.data.user)
      getApp().ports.hfgd({
        data: data
      }).then((res) => {
        var res = res.data;
        that.user(res.marketer)
        console.log(res, '成功折扣');
        res.time = app.timeFormat(res.createTime, true)
        if (res.stage == 5) that.data.btnText = '订单完成'
        if(res.stage == 2){
          that.setData({
            show:true
          })
        }
        if (res.createTime) {
          step_list[0].time = app.timeFormat(res.createTime, false, true)
        }
        // res.comment = res.housePreuploadOrder.comment
        // res.rate = res.housePreuploadOrder.rate
        that.setData({
          list: res,
          typeId: res.demandOrderId,
          client: that.data.user.client,
          step_list: that.data.step_list,
          btnText: that.data.btnText
        })
        console.log(that.data.list, 'list========')
        that.recommend(that.data.user.client)
        that.history()
      }).catch(() => {
        console.error('出啥错了？');
      });
    } else if (type == 6) { //增值
      data.valueAddedOrderId = that.data.id
      getApp().ports.zzgd({
        data: data
      }).then((res) => {
        var user = that.data.user;
        var res = res.data;
        res.time = app.timeFormat(res.createTime, true);
        user.createTime = app.timeFormat(res.createTime);
        step_list[0].time = app.timeFormat(res.createTime, false, true)
        step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
        step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
        step_list[3].time = app.timeFormat(res.interviewTime, false, true)
        step_list[4].time = app.timeFormat(res.finishTime, false, true)
        that.user(res.marketer)
        var ys = ['200万以下', '200-500万', '500-100万', '1000万以上'];
        var sr = ['5000元-10000元', '10000元-15000元', '15000元以上']
        user.ys = ys[res.valueAddedOrder.budgetPriceYuan]
        var zy = ['个体户', '政府单位', '企业单位'];
        var hy = ['已婚', '未婚', '离异'];
        var zq = ['1个月','2个月','3个月','3个月以上']
        res.zy = '工作单位：'+zy[res.valueAddedOrder.workType]
        res.zq = '申请周期：'+zq[res.valueAddedOrder.applyCycle]
        var zj = ['50万以下','50万-150万','150万-300万','300万以上'];
        res.zj = '申请金额：'+zj[res.valueAddedOrder.budgetPriceYuan]
        user.sr = sr[res.valueAddedOrder.monthlyIncome]
        user.hy = hy[res.valueAddedOrder.marriage]
        console.log(that.data.user, '成功');
        res.comment = res.valueAddedOrder.comment
        res.rate = res.valueAddedOrder.rate
        if (res.stage == 5) that.data.btnText = '订单待评价'
        if(res.stage ==2){that.setData({historyShow:true})}
        that.setData({
          list: res,
          client: res.valueAddedOrder.client,
          // house:res.discount_house_bookingorder.discount_house,
          step_list: step_list,
          user: user,
          typeId: res.valueAddedOrderId,
          btnText: that.data.btnText,
        })
        that.recommend(that.data.user.client)
        that.history()
        // var res = res.data;
        // that.user(res.marketer)
        // console.log(res, '成功');
        // res.time = app.timeFormat(res.createTime, true)
        // if (res.createTime) {
        //   step_list[0].time = app.timeFormat(res.createTime, false, true)
        // }
        // if (res.stage == 5) that.data.btnText = '订单完成'
        // if(res.stage == 2){
        //   that.setData({
        //     show:true
        //   })
        // }

        // // res.comment = res.housePreuploadOrder.comment
        // // res.rate = res.housePreuploadOrder.rate
        // that.setData({
        //   list: res,
        //   client: that.data.user.client,
        //   step_list: that.data.step_list,
        //   btnText: that.data.btnText
        // })
        // that.recommend(that.data.user.client)
        // that.history()
      }).catch(() => {
        console.error('出啥错了？');
      });
    }

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var titles = ['', '优选预约跟单', '折扣预约跟单', '放盘预约跟单', '尽调预约跟单', '好房预约跟单', '增值预约跟单']
    wx.setNavigationBarTitle({
      title: titles[Number(options.type)]
    })
    var status = that.data.status;
    that.setData({
      type: options.type,
      user: JSON.parse(decodeURIComponent(options.user)),
    })
    // console.log(that.data.user, "user==========");
    var data = {
      "stage": 0,
    }
    if (options.typeId) {
      that.yyxq(options.typeId)
      that.setData({
        pj: true
      })
    } else {
      var data = {}
      that.setData({
        id: options.id
      })
      that.api(data)
    }
    // that.history()
  },
  yyxq(typeId) {
    var that = this;
    var step_list = that.data.step_list;
    var type = Number(that.data.type);
    var user = that.data.user;
    console.log(type)
    switch (type) {
      case 3:
        getApp().ports.fanpgdxq({ //放盘
          id: typeId
        }).then((res) => {
          var res = res.data;
          // res.time = app.timeFormat(res.createTime, true)
          user.createTime = app.timeFormat(res.housePreuploadOrder.createTime);
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.finishTime, false, true)
          user.clientName = res.housePreuploadOrder.clientName;
          user.title = res.housePreuploadOrder.title
          user.builtUpAreaSquareCentimeter = res.housePreuploadOrder.builtUpAreaSquareCentimeter
          user.intentionPriceYuan = res.housePreuploadOrder.intentionPriceYuan
          if(res.stage ==2){that.setData({historyShow:true})}
          res.comment = res.housePreuploadOrder.comment
          res.rate = res.housePreuploadOrder.rate
          if(res.housePreuploadOrder.finished == 1) that.data.btnText = '订单待评价'  
          console.log(res, '成功');
          that.setData({
            list: res,
            client: that.data.user.client,
            house: res.housePreuploadOrder.foreclosedHouse,
            step_list: step_list,
            user: that.data.user,
            typeId: res.housePreuploadOrderId,
            btnText: that.data.btnText,
            finished:res.housePreuploadOrder.finished
          })
          that.user(res.marketer)
          that.recommend(res.housePreuploadOrder.client)
          that.history()
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
      case 5:
        getApp().ports.hfgdxq({ //好房
          id: typeId
        }).then((res) => {
          var res = res.data;
          console.log('好房预约')
          res.time = app.timeFormat(res.createTime, true)
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.finishTime, false, true);
          var ys = ['200万以下', '200-500万', '500-100万', '1000万以上'];
          var mj = ['50㎡以下', '50㎡-90㎡', '90㎡-144㎡', , '144㎡以上'];
          var md = ['刚需自住', '投资捡漏', '自住+捡漏']
          if (res.purchaseReason) res.md = md[res.purchaseReason]
          if (res.houseArea) res.mj = mj[res.houseArea];
          if (res.totalBudgetPriceYuan) res.ys = ys[res.totalBudgetPriceYuan]
          user.createTime = app.timeFormat(res.demandOrder.createTime);
          user.title = res.demandOrder.title;
          user.md = md[res.demandOrder.purchaseReason];
          user.ys = ys[res.demandOrder.totalBudgetPriceYuan];
          user.livingroom = res.demandOrder.livingroom;
          user.bedroom = res.demandOrder.bedroom;
          user.mj = mj[res.demandOrder.houseArea];
          user.comment = res.demandOrder.comment;
          user.rate = res.demandOrder.rate;
          if (res.stage == 5) that.data.btnText = '订单待评价';
          if(res.stage ==2){that.setData({historyShow:true})}
          if (res.demandOrder.comment) res.comment = res.demandOrder.comment
          if (res.demandOrder.rate) res.rate = res.demandOrder.rate
          console.log(res, '成功');
          that.setData({
            list: res,
            client: res.demandOrder.client,
            house: res.demandOrder,
            step_list: step_list,
            user: user,
            typeId: res.demandOrderId,
            btnText: that.data.btnText,
          })
          that.user(res.marketer)
          that.recommend(res.demandOrder.client)
          that.history()
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
      case 6:
        getApp().ports.zzgdxq({ //增值
          id: typeId
        }).then((res) => {
          var res = res.data;
          res.time = app.timeFormat(res.createTime, true);
          user.createTime = app.timeFormat(res.valueAddedOrder.createTime);
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.finishTime, false, true)
          that.user(res.marketer)
          var ys = ['200万以下', '200-500万', '500-100万', '1000万以上'];
          var sr = ['5000元-10000元', '10000元-15000元', '15000元以上']
          user.ys = ys[res.valueAddedOrder.budgetPriceYuan]
          var zy = ['个体户', '政府单位', '企业单位'];
          var hy = ['已婚', '未婚', '离异'];
          var zq = ['1个月','2个月','3个月','3个月以上']
          res.zy = '工作单位：'+zy[res.valueAddedOrder.workType]
          res.zq = '申请周期：'+zq[res.valueAddedOrder.applyCycle]
          var zj = ['50万以下','50万-150万','150万-300万','300万以上'];
          res.zj = '申请金额：'+zj[res.valueAddedOrder.budgetPriceYuan]
          user.sr = sr[res.valueAddedOrder.monthlyIncome]
          user.hy = hy[res.valueAddedOrder.marriage]
          console.log(that.data.user, '成功');
          res.comment = res.valueAddedOrder.comment
          res.rate = res.valueAddedOrder.rate
          if (res.stage == 5) that.data.btnText = '订单待评价'
          if(res.stage ==2){that.setData({historyShow:true})}
          that.setData({
            list: res,
            client: res.valueAddedOrder.client,
            // house:res.discount_house_bookingorder.discount_house,
            step_list: step_list,
            user: user,
            typeId: res.valueAddedOrderId,
            btnText: that.data.btnText,
          })
          that.recommend(res.valueAddedOrder.client)
          that.history()
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
    }

  },
  history() {
    var that = this;
    var listId = [];
    var houses = [];
    app.ports.userHistory({
      id: that.data.client
    }).then(res => {
      res.data.results.forEach(item => {
        var status = item.houseCategory == 1 ? 0 : 1;
        item.url = '../details/details?id=' + item.houseId + '&status='+status
      })
      that.setData({
        history: res.data
      })
      // console.log(res.data)
      // for (var i = 0; i < res.data.houses.buckets.length; i++) {
      //   console.log(res.data.houses.buckets[i].latest_access_logs.hits.hits[0]._source)
      //   listId.push(res.data.houses.buckets[i].latest_access_logs.hits.hits[0]._source.house_id)
      //   houses.push(res.data.houses.buckets[i].latest_access_logs.hits.hits[0])
      // }

      // app.ports.gethouses({
      //   data: listId
      // }).then(obj => {
      //   var obj = obj.data;
      //   for (let i = 0; i < obj.results.length; i++) {
      //     obj.results[i].house_category = '折扣'
      //     for (var j = 0; j < houses.length; j++) {
      //       if (obj.results[i].id == res.data.houses.buckets[j].latest_access_logs.hits.hits[0]._source.house_id) {
      //         obj.results[i].browseDate = app.timeFormat(res.data.houses.buckets[j].latest_access_logs.hits.hits[0]._source.access_time, true)
      //         obj.results[i].browseTime = res.data.houses.buckets[j].latest_access_logs.hits.hits[0]._source.access_interval_seconds
            
      //         // obj.results[i].type = res.data.houses.buckets[j].latest_access_logs.hits.hits[0]._source.house_category
      //       }
      //     }
      //     if (obj.results[i].type == 1) {
      //       obj.results[i].house_category = '优选'
      //       obj.results[i].tags = [{
      //         name: obj.results[i].builtUpAreaSquareCentimeter + '㎡'
      //       }, {
      //         name: obj.results[i].discount_rate + '折'
      //       }, {
      //         name: obj.results[i].stage
      //       }]
      //       obj.results[i].market_price_yuan = Math.floor((obj.results[i].market_price_yuan / 10000));
      //       obj.results[i].price_yuan = Math.floor((obj.results[i].price_yuan / 10000));
      //       obj.results[i].time = app.timeFormat(obj.results[i].start_time) + '-' + app.timeFormat(obj.results[i].end_time)
      //     } else {
      //       obj.results[i].time = app.timeFormat(obj.results[i].upload_time)
      //     }
      //     obj.results[i].url = '../details/details?id=' + obj.results[i].id
      //   }
      //   that.setData({
      //     history: obj
      //   })
      // }).catch(() => {
      //   console.error('浏览记录列表')
      // })
    }).catch(() => {
      console.error('浏览记录列表')
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

 
  step(e) {
    var that = this;
    console.log(e.detail);
    if (e.detail == 1) {
      that.setData({
        active: e.detail
      })
    }
  },
  choose(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    console.log(index)
    var select = this.data.select;
    if (select[index].index != 1) {
      select[index].index = 1
    } else {
      select[index].index = 0
    }
    that.setData({
      select: select
    })
    console.log(select)
  },
  customize(e) {
    var that = this;
    that.setData({
      customize: e.detail.value
    })
  },
  showModel(e) {
    var that = this;
    that.setData({
      Model: true,
      customize: ''
    })
  },
  activeBtn() {
    var that = this;
    var list = that.data.list;
    var stage = that.data.list.stage;
    if (stage < 5) {
      stage += 1
    }
    console.log(list, 'list======')
    // var btnText = '下一步';
    var show = that.data.show;
    var data = {
      stage: stage
    }
    if (list.stage == 5) {
      if (that.data.type == 3) {
        that.sign();
      } else {
        wx.showToast({
          title: '状态完成',
        })
      }
    } else {
      that.gdzt(data);
    }

    // if (list.stage < 4 && list.stage != 4 && list.stage != 5 && list.stage != 0) {
    //   list.stage += 1
    // } else if (list.stage == 4) {
    //   list.stage += 1
    //   btnText = '立即签约'
    // } else if (list.stage == 5) {

    //   btnText = '立即签约'
    // } else if (list.stage == 0) {
    //   show = true
    //   list.stage = 1
    // }
    console.log(list)
    that.setData({
      list: list,
      show: show
    })
  },
  gdzt(data) {
    var that = this;
    var step_list = that.data.step_list;
    switch (Number(that.data.type)) {
      case 3:
        getApp().ports.fanpgdzt({
          data: data,
          id: that.data.list.id
        }).then((res) => {
          var res = res.data;
          that.user(res.marketer)
          res.time = app.timeFormat(res.createTime, true)
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.finishTime, false, true)
          if (res.stage == 5) {
            that.data.btnText = '订单已完成'
          }
          if(res.stage == 2) {
            that.setData({
              historyShow:true
            })
          }
          if(res.stage == 3){
            wx.setClipboardData({
              data: that.data.user.phone,
              success: function (res) {
                wx.getClipboardData({
                  success: function (res) {
                    wx.showToast({
                      title: '复制手机号码成功',
                      icon:'none'
                    })
                  }
                })
              }
            })
          }
          if(res.stage == 4){
            that.setData({
              dial:true
            })
          }
          that.setData({
            list: res,
            step_list: step_list,
            btnText: that.data.btnText
          })
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
      case 5:
        getApp().ports.hfgdzt({
          data: data,
          id: that.data.list.id
        }).then((res) => {
          var res = res.data;
          that.user(res.marketer)
          res.time = app.timeFormat(res.createTime, true);
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.finishTime, false, true)
          if (res.stage == 5) {
            that.data.btnText = '订单已完成'
          }
          if(res.stage == 2) {
            that.setData({
              historyShow:true
            })
          }
          if(res.stage == 3){
            wx.setClipboardData({
              data: that.data.user.phone,
              success: function (res) {
                wx.getClipboardData({
                  success: function (res) {
                    wx.showToast({
                      title: '复制手机号码成功',
                      icon:'none'
                    })
                  }
                })
              }
            })
          }
          if(res.stage == 4){
            that.setData({
              dial:true
            })
          }
          that.setData({
            list: res,
            step_list: step_list,
            btnText: that.data.btnText
          })
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
      case 6:
        getApp().ports.zzgdzt({
          data: data,
          id: that.data.list.id
        }).then((res) => {
          var res = res.data;
          let user = that.data.user;
          that.user(res.marketer)
          res.time = app.timeFormat(res.createTime, true);
          user.createTime = app.timeFormat(res.createTime);
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.finishTime, false, true)
          var ys = ['200万以下', '200-500万', '500-100万', '1000万以上'];
          var sr = ['5000元-10000元', '10000元-15000元', '15000元以上']
          user.ys = ys[res.valueAddedOrder.budgetPriceYuan]
          var zy = ['个体户', '政府单位', '企业单位'];
          var hy = ['已婚', '未婚', '离异'];
          var zq = ['1个月','2个月','3个月','3个月以上']
          res.zy = '工作单位：'+zy[res.valueAddedOrder.workType]
          res.zq = '申请周期：'+zq[res.valueAddedOrder.applyCycle]
          var zj = ['50万以下','50万-150万','150万-300万','300万以上'];
          res.zj = '申请金额：'+zj[res.valueAddedOrder.budgetPriceYuan]
          user.sr = sr[res.valueAddedOrder.monthlyIncome]
          user.hy = hy[res.valueAddedOrder.marriage]
          console.log(that.data.user, '成功');
          res.comment = res.valueAddedOrder.comment
          res.rate = res.valueAddedOrder.rate
          // if (res.stage == 5) that.data.btnText = '订单待评价'
          // if(res.stage ==2){that.setData({historyShow:true})}
          
          if (res.stage == 5) {
            that.data.btnText = '订单已完成'
          }
          if(res.stage == 2) {
            that.setData({
              historyShow:true
            })
          }
          if(res.stage == 3){
            wx.setClipboardData({
              data: that.data.user.phone,
              success: function (res) {
                wx.getClipboardData({
                  success: function (res) {
                    wx.showToast({
                      title: '复制手机号码成功',
                      icon:'none'
                    })
                  }
                })
              }
            })
          }
          if(res.stage == 4){
            that.setData({
              dial:true
            })
          }
          // that.setData({
          //   list: res,
          //   step_list: step_list,
          //   btnText: that.data.btnText
          // })

          that.setData({
            list: res,
            // client: res.valueAddedOrder.client,
            // house:res.discount_house_bookingorder.discount_house,
            step_list: step_list,
            user: user,
            // typeId: res.valueAddedOrderId,
            btnText: that.data.btnText,
          })
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
    }
  },
  CloseHide() {
    this.setData({
      CloseShow: false
    });
  },
  sign() {
    var that = this;
    var data = {
      client: that.data.client
    };
    var obj = {finished : 1}
    wx.showModal({
      title: '即将发起签约订单',
      content: '请确保用户已准备好签约信息',
      success(res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '../../subpackages/pages/listing/listing?client=' + that.data.user.client,
          })
          that.setData({
            btnText:'订单待评价'
          })
           that.yyxg(obj)
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  onClickShow() {
    this.setData({
      show: true
    });
  },

  onClickHide() {
    this.setData({
      historyShow: false
    });
  },

  noop() {},
  onChange(event) {
    this.setData({
      value: event.detail,
    });
  },
  getUserInfo(event) {
    var that = this;
    var select = that.data.select;
    select.push({
      name: that.data.customize,
      index: 0
    });
    this.setData({
      Model: false,
      select: select
    });
  },

  onClose() {
    this.setData({
      Model: false
    });
  },
  navTo: function (e) { //跳转
    var url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url
    })
  },
  yyxg(data) {
    var that = this;
    switch (Number(that.data.type)) {
      case 3:
        getApp().ports.fanpgdzt({
          data: data,
          id: that.data.list.id
        }).then((res) => {
          var res = res.data;
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
    }
  },
})